#include <bits/stdc++.h>

using namespace std;

const int MAXN = 5e5+10;

typedef struct {int v,nxt;}edge;

int n,h[MAXN],cnt,root;
long long f[MAXN],siz[MAXN],a[MAXN];
double ans = -99999999999;
edge e[MAXN<<1];
bool isleaf[MAXN];

void link(int x,int y){e[++cnt] = edge{y,h[x]};h[x] = cnt;}

void dfs(int x,int p){
	isleaf[x] = 1;
	for(int i = h[x];i;i = e[i].nxt){
		int y = e[i].v; if(y == p) continue;
		dfs(y,x);isleaf[x] = 0;
		siz[x] += siz[y];
		f[x] += f[y] + siz[y] * a[x];
	}
	if(isleaf[x]) {
		siz[x] = 1;
		f[x] = a[x];
	}
}

void dp(int x,int p){
	ans = max(ans,(double)f[x]/(siz[root]-isleaf[x]));
	for(int i = h[x];i;i = e[i].nxt){
		int y = e[i].v; if(y == p) continue;
		if(isleaf[y]) f[y] = f[x] - a[x] + a[y] * (siz[root] - 2);
		else f[y] = f[x] - siz[y] * a[x] + (siz[root]-siz[y]) * a[y];
		dp(y,x);
	}
}

int main(){
	scanf("%d",&n);
	for(int i = 1;i < n;i++){
		int x,y;scanf("%d %d",&x,&y);
		link(x,y);link(y,x);
	}
	for(int i = 1;i <= n;i++) scanf("%lld",&a[i]);
	for(int i = 1;i <= n;i++) if(e[h[i]].nxt) {root = i;break;}
	dfs(root,0);
	dp(root,0);
	printf("%.4lf\n",ans);
	return 0;
}
